﻿if exists (select 1
   from dbo.sysreferences r join dbo.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('SYSTEM_CODE') and o.name = 'FK_SYSTEM_C_REFERENCE_SYSTEM_C')
alter table SYSTEM_CODE
   drop constraint FK_SYSTEM_C_REFERENCE_SYSTEM_C
go

if exists (select 1
            from  sysobjects
           where  id = object_id('SYSTEM_CODE')
            and   type = 'U')
   drop table SYSTEM_CODE
go

/*==============================================================*/
/* Table: SYSTEM_CODE                                           */
/*==============================================================*/
create table SYSTEM_CODE (
   CODEID               varchar(36)          not null,
   CODETYPE             varchar(20)          null,
   CODENAME             varchar(36)          null,
   REMARK               varchar(255)         null,
   ENABLEEDIT           char(1)              null,
   CREATEID             char(36)             null,
   CREATEDATE           DATE                 null,
   UPDATEID             char(36)             null,
   UPDATEDATE           DATE                 null,
   constraint PK_SYSTEM_CODE primary key (CODEID)
)
go

alter table SYSTEM_CODE
   add constraint FK_SYSTEM_C_REFERENCE_SYSTEM_C foreign key (CODETYPE)
      references SYSTEM_CODE_TYPE (CODETYPE)
go
